package com.core.dao.mybatismysql;

import com.core.bean.Online;
import com.core.utils.GsonUtils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class OnlineDaoSub extends OnlineDao {
    @Override
    public int add(Online entity) throws Exception {
        String Sql = "INSERT INTO `lct_online` VALUES(?,?,?,?,?,?,?,?) ";
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://58.250.17.31:3036/ljsw_tomcat_project_01",
                "tomcat","123456");
        PreparedStatement ps = null;
        try{
            ps = connection.prepareStatement(Sql);
            ps.setString(1,entity.getId());
            ps.setString(2, GsonUtils.toJsonStr(entity.getUser()));
            ps.setObject(3,entity.getLoginTime());
            ps.setString(4,entity.getIp());
            ps.setInt(5,entity.getPort());
            ps.setString(6,entity.getDevInfo());
            ps.setString(7,entity.getOs());
            ps.setString(8,entity.getToKen());
            int i = ps.executeUpdate();
            return i;
        }catch (Exception e){
            throw e;
        }finally {
            ps.close();
            connection.close();
        }
    }

    @Override
    public int modify(Online entity) throws Exception {
        return -1;
    }
}
